<template>
    <div>
        <div class="search-content">
            <el-button type="primary" @click="openAll">全部开启</el-button>
			<el-button type="primary" @click="closeAll">全部关闭</el-button>
			<el-button type="primary" @click="getListData">刷新</el-button>
        </div>
        <div class="search-list">
            <el-table :data="goodsList" border :height="oHeight" :fit="true">
                <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                <el-table-column align="center" prop="id" label="ID" min-width="60"></el-table-column>
				<el-table-column align="center" prop="description" label="服务名称" min-width="60"></el-table-column>
                <el-table-column align="center" prop="job_start_time" label="开始时间" min-width="130" #default="{row}">
					{{row.job_start_time|dateFormatter('YYYY-MM-DD HH:mm:ss')}}
				</el-table-column>
                <el-table-column align="center" prop="job_end_time" label="结束时间" min-width="110" #default="{row}">
					{{row.job_end_time|dateFormatter('YYYY-MM-DD HH:mm:ss')}}
				</el-table-column>
                <el-table-column align="center" prop="executed_time" label="最近触发时间" min-width="170" #default="{row}">
					{{row.executed_time|dateFormatter('YYYY-MM-DD HH:mm:ss')}}
				</el-table-column>
                <el-table-column align="center" prop="job_status" label="状态" min-width="70"  #default="{row}">
					{{row.job_status==="0"?"停止":''}}
					{{row.job_status==="1"?"开启":''}}
					{{row.job_status==="2"?"运行中":''}}
				</el-table-column>
                <el-table-column
                    fixed="right"
                    align="center"
                    prop="isInitiative"
                    label="操作"
                    min-width="120"
                    #default="{row}"
                >
                    <div style="color: #5790bb">
						<el-button v-if="row.job_status==='0'" type="primary" @click="openTask(row.id)">开启</el-button>
                        <el-button v-else type="primary" @click="closeTask(row.id)">关闭</el-button>
                        
                    </div>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group">
                    <!-- <el-button type="primary" class="btn-bottom" @click="expertData">导出检索数据</el-button> -->
                </div>
                <!--分页部分-->
                <div class="paginationOne">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="searchContent.currentPage"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="searchContent.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total*1"
                    ></el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { resize } from "@/common/js/height.js";
import { dateFormatter, objScreen } from "@/common/js/util";
export default {
    data() {
        return {
            goodsList: [],
            oHeight: 800,
            searchContent: {
                currentPage: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
                supplier_product_id: '',
                store_id: '',
                productName: '',
                storeName: ''
            },
            searchObj: {},
            total: 0,
        };
    },
    created() {
        this.getListData();
    },
    methods: {
		closeAll(){
			this.$http.post("/admin/dataService/index.php?act=merchantSet&op=closeAll").then(res => {
                if (res.code === 1) {
					this.$message.success(res.msg);
                } else if (res) {
                    this.$message.error(res.msg);
                }
            }).catch(err => {
                this.$message.error(err);
            })
		},
		openAll(){
			this.$http.post("/admin/dataService/index.php?act=merchantSet&op=openAll").then(res => {
                if (res.code === 1) {
					this.$message.success(res.msg);
                } else if (res) {
                    this.$message.error(res.msg);
                }
            }).catch(err => {
                this.$message.error(err);
            })
		},
		closeTask(id){
			this.$http.post("/admin/dataService/index.php?act=merchantSet&op=closeTask",{id}).then(res => {
                if (res.code === 1) {
					this.$message.success(res.msg);
                } else if (res) {
                    this.$message.error(res.msg);
                }
            }).catch(err => {
                this.$message.error(err);
            })
		},
		openTask(){
			this.$http.post("/admin/dataService/index.php?act=merchantSet&op=openTask").then(res => {
                if (res.code === 1) {
					this.$message.success(res.msg);
                } else if (res) {
                    this.$message.error(res.msg);
                }
            }).catch(err => {
                this.$message.error(err);
            })
		},
        getListData() {
            var data = this.searchObj;
            data.currentPage = this.searchContent.currentPage;
            data.eachNum = this.searchContent.pageSize;
            this.$http.post('/admin/dataService/index.php?act=merchantSet&op=scheduleList').then((res) => {
                if (res.code === 1) {
                    this.total = res.data.total;
                    this.goodsList = res.data.list;
                    // this._message('success', res.msg);
                    // this.getListData();
                } else {
                    this.total = 0;
                    this.goodsList = [];
                    this._message('error', res.msg);
                }
            }).catch(err => {
                this._message('error', err);
            })
        },
        handleSizeChange(pageSize) {
            localStorage.setItem('pageSize', pageSize);
            this.searchContent.pageSize = pageSize;
            this.searchContent.currentPage = 1;
            this.getListData();
        },
        handleCurrentChange(page) {
            this.searchContent.currentPage = page;
            this.getListData();
        },
    },
    mounted() {
        resize(this)
    },
};
</script>
<style lang="scss" scoped>
.bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.search-content-input {
    width: 200px;
}
</style>